package cn.qayy.testmybatis;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.alibaba.fastjson.JSON;

import cn.qayy.pojo.User;
import cn.qayy.service.IUserService;
import cn.qayy.utils.MyMD5;


@RunWith(SpringJUnit4ClassRunner.class)	//表示继承了SpringJUnit4ClassRunner类
@ContextConfiguration(locations = {"classpath:spring-mybatis.xml"})

public class TestMyBatis {

	private static Logger logger=Logger.getLogger(TestMyBatis.class);
	@Resource 
	private  IUserService userService=null;
	
	@Test
	public void testSave(){
		User user = new User();
		user.setUserName("jobs1127");
		user.setPassword(MyMD5.toMd5("jobs1226"));
		user.setAge(18);
		userService.saveUser(user);
	}
	
	@Test
	public void testQuery(){
		User user=userService.getUserById(4);
		//打出日志
		logger.info(JSON.toJSONString(user));
	}
	
	
}
